import numpy as np
import numba as nb
from numba import cuda
from math import exp, ceil
from ..utils import get_grid_1d, assume_ndarray, flatten


@cuda.jit()
def _gpu_absolute(a: np.ndarray, b: np.ndarray):
    x = cuda.grid(1)
    if x < a.shape[0]:
        b[x] = abs(a[x])


def absolute(a: np.ndarray):
    assert isinstance(a, np.ndarray)

    b = np.empty_like(a)

    grid, block = get_grid_1d(a.size)
    _gpu_absolute[grid, block](flatten(a), flatten(b))
    return b
